package net.toby200.canalbuddy.notices.gcm;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

import java.util.logging.Logger;

/**
 * Created by toby on 31/07/2014.
 */
public class GcmReceiver extends WakefulBroadcastReceiver {

    private static final Logger LOG = Logger.getLogger(GcmReceiver.class.getName());

    @Override
    public void onReceive(Context context, Intent intent) {
        LOG.info("onReceive, Intent action=" + intent.getAction());

        if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
            LOG.info("Received GCM message");
        } else if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            LOG.info("Phone boot completed");
        }
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));

        setResultCode(Activity.RESULT_OK);
    }
}
